package top.codedance.iotp.server.net.handle;

import top.codedance.iotp.common.entity.CommonEntity;
import top.codedance.iotp.server.ServerApplication;
import cd.io.netty.channel.ChannelHandlerContext;
import cd.io.netty.channel.SimpleChannelInboundHandler;
import cd.io.netty.util.ReferenceCountUtil;

public class HttpCounterHandler extends SimpleChannelInboundHandler<CommonEntity> {

    @Override
    protected void messageReceived(ChannelHandlerContext channelHandlerContext, CommonEntity commonEntity) throws Exception {
        ReferenceCountUtil.release(commonEntity);
        channelHandlerContext.fireChannelRead(commonEntity); //向后传递
    }

    @Override
    public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
        super.channelRegistered(ctx);
        ServerApplication.httpConnectCounter.incrementAndGet();
    }

    @Override
    public void channelUnregistered(ChannelHandlerContext ctx) throws Exception {
        super.channelUnregistered(ctx);
        ServerApplication.httpConnectCounter.decrementAndGet();
    }

}